using System;
using UnityEngine;

[Serializable]
public class TTCameraBehaviourFollowPosition : TTCameraBehaviour
{
	public Vector3 cameraOffset;

	public Vector3 rotation;

	public float minZTableLength = 1f;

	private Vector3 hitPosition;

	private float cameraOffsetSignX;

	private float cameraOffsetSignZ;

	public void SetupUpdate(Vector3 hitPosition, float cameraOffsetSignX, float cameraOffsetSignZ)
	{
		this.hitPosition = hitPosition;
		this.cameraOffsetSignX = cameraOffsetSignX;
		this.cameraOffsetSignZ = cameraOffsetSignZ;
	}

	public override void Start(Camera cam, TTCameraController camController, TTCameraOptions cameraOptions)
	{
		base.Start(cam, camController, cameraOptions);
		camController.onHitPointUpdatePos = SetupUpdate;
	}

	public override void Update()
	{
		camera.transform.position = Vector3.Lerp(camera.transform.position, DesiredPosition(), RealTime.deltaTime * moveSpeed);
		camera.transform.rotation = Quaternion.Lerp(camera.transform.rotation, Quaternion.Euler(rotation), RealTime.deltaTime * rotationSpeed);
		camera.fieldOfView = Mathf.Lerp(camera.fieldOfView, fov, RealTime.deltaTime * rotationSpeed);
	}

	protected override Vector3 DesiredPosition()
	{
		Vector3 result = hitPosition.OnGround() + Vector3.right * Mathf.Sign(cameraOffsetSignX) * cameraOffset.x + new Vector3(0f, cameraOffset.y, Mathf.Sign(cameraOffsetSignZ) * cameraOffset.z);
		result.z = Mathf.Sign(result.z) * Mathf.Max(Mathf.Abs(result.z), minZTableLength * Table.halfLength);
		return result;
	}
}
